package com.ws.axis.casino;

import javax.naming.Context;

import com.ws.bean.CasinoAppInterface;
import com.ws.helper.CasinoAppReturnObject;

/**
 * @author C707538
 *
 */
public class CasinoApp {

	private CasinoAppInterface casinoAppInterface = null;

	public CasinoApp() {
		super();
		if (casinoAppInterface == null) {
            Context ctx = null;
            try {
                ctx = new javax.naming.InitialContext();
                casinoAppInterface = (CasinoAppInterface) ctx.lookup("casino/CasinoAppBean/remote");
            } catch (javax.naming.NamingException e) {
                e.printStackTrace(System.out);
            }
        }
	}

	/**
	 * Set up a new game with a given amount of players.
	 * 
	 * @param anAmountOfPlayers
	 */
	public void initializeGame(int anAmountOfPlayers) {
		System.out.println("Initialize a new game");
		// initCasinoBean();
		if (this.casinoAppInterface != null) {
			this.casinoAppInterface.initializeGame(anAmountOfPlayers);
		}
		System.out.println(anAmountOfPlayers
				+ " players will participate the game");
	}

	/**
	 * This request participates on the current round. There is a ReturnObject
	 * available with a value of each row for the gambling-app. Also there will
	 * be set the flag if the player won.
	 * 
	 * @param aRequest
	 * @return CasinoAppReturnObject
	 */
	public CasinoAppReturnObject getPot() {
		CasinoAppReturnObject retObject = null;
		// initCasinoBean();
		if (this.casinoAppInterface != null) {
			retObject = this.casinoAppInterface.faitesLesJeux();
		}
		if (retObject == null) {
			retObject = getaNotWinningReturnObject();
		}
		return retObject;
	}

	private CasinoAppReturnObject getaNotWinningReturnObject() {
		CasinoAppReturnObject retObject = new CasinoAppReturnObject();
		retObject.setPlayerWins(false);
		retObject.setNumberRow1(1);
		retObject.setNumberRow2(2);
		retObject.setNumberRow3(3);
		return retObject;
	}
}
